package org.uu.repository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.uu.bean.User;

@Repository
public class UserDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    public int addUser(User user) {
        return jdbcTemplate.update("insert into u(id, name, role)");
    }

    public User getUserById(User user) {
        return jdbcTemplate.queryForObject("select * from u where id = ?", new BeanPropertyRowMapper<>(User.class),
                user.getId());
    }

    public User checkUser(User user) {
        return jdbcTemplate.queryForObject("select id, name, role from u where id = ? and name = ?",
                new BeanPropertyRowMapper<>(User.class), user.getId(), user.getName());
    }
}
